package com.cn.test;

import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.cn.test.base.BaseActivity;
import com.cn.test.base.BaseView;
import com.cn.test.model.response.LoginRegisterResult;
import com.cn.test.mvp.presenter.LoginUserPresenter;
import com.cn.test.mvp.presenter.view.LoginUserView;
import com.cn.test.ui.example.EmptyActivity;
import com.cn.test.util.PrefShare;
import com.cn.test.util.ToastUtil;
import com.cn.test.xuanhttplibrary.okhttp.HttpUtils;
import com.cn.test.xuanhttplibrary.okhttp.callback.BaseCallback;
import com.cn.test.xuanhttplibrary.okhttp.result.ObjectResult;
import com.cn.test.xuanhttplibrary.okhttp.result.Result;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import okhttp3.Call;

/**
 * Created by Administrator on 2018/1/2.
 */

public class MainActivity extends BaseActivity<LoginUserView, LoginUserPresenter> implements LoginUserView {

    @BindView(R.id.nav_home_img)
    ImageView navHomeImg;
    @BindView(R.id.nav_home_text)
    TextView navHomeText;
    @BindView(R.id.nav_home_tab)
    RelativeLayout navHomeTab;
    @BindView(R.id.nav_mine_img)
    ImageView navMineImg;
    @BindView(R.id.nav_mine_text)
    TextView navMineText;
    @BindView(R.id.nav_mine_tab)
    RelativeLayout navMineTab;

    @BindView(R.id.nav_subscribe_img)
    ImageView navSubscribeImg;
    @BindView(R.id.nav_subscribe_text)
    TextView navSubscribeText;
    @BindView(R.id.nav_subscribe_tab)
    RelativeLayout navSubscribeTab;
    @BindView(R.id.nav_release_img)
    ImageView navReleaseImg;
    @BindView(R.id.nav_release_text)
    TextView navReleaseText;
    @BindView(R.id.nav_release_tab)
    RelativeLayout navReleaseTab;


    @BindView(R.id.nav_todaypolicy_img)
    ImageView navTodaypolicyImg;
    @BindView(R.id.nav_todaypolicy_text)
    TextView navTodaypolicyText;
    @BindView(R.id.nav_todaypolicy_tab)
    RelativeLayout navTodaypolicyTab;


    //手机连续按返回键两次的间隔时间
    private long mExitTime;
    private static final String[] FRAGMENT_TAG = {"mBossFragment", "mAppointmentFragment", "mReleaseFragment", "mMineFragment"};
    private static final String PRV_SELINDEX = "PREV_SELINDEX";
    private int selindex = 0;


    AnimationDrawable animation1;

    public MainActivity() {

    }

    private void initPermission() {
    }


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("Debug", "到达oncreate中------------");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("Debug", "到达onresume中");
//
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putInt(PRV_SELINDEX, selindex);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected int getNormalLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected int getErrorLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected LoginUserPresenter createPresenter() {
        return new LoginUserPresenter(this, this);
    }

    @Override
    protected void initViewsAndEvents() {
    }

    @Override
    public void requestFailed(String message) {

    }


    @OnClick({R.id.nav_home_tab})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.nav_home_tab:
                login();
                break;
        }
    }

    /**
     * @param
     */
    private void login() {
        String ANDROID_ID = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);
        Map<String, String> params = new HashMap<>();
        params.put("token", ANDROID_ID);          // 账号登陆的时候需要MD5加密，服务器需求
        HttpUtils.get().url(AppConfig.USER_LOGIN)
                .params(params)
                .build()
                .execute(new BaseCallback<LoginRegisterResult>(LoginRegisterResult.class) {
                    @Override
                    public void onResponse(ObjectResult<LoginRegisterResult> result) {
                        Log.d("Debug", "到达请求这里---");
                    }

                    @Override
                    public void onError(Call call, Exception e) {
                    }
                });
    }

}
